package com.test09_抽象类和接口;

/**
 * 工厂设计模式
 */
public class YootkDemo_06 {

    public static void main(String[] args) {
        IBook6 book = BookFactory.getInstance("math");
        book.read();
    }
}

interface IBook6 {
    public void read();
}

class ProgramBook6 implements IBook6 {
    @Override
    public void read() {
        System.out.println("【ProgramBook】认真学习Java开发");
    }
}

class MathBook6 implements IBook6 {
    @Override
    public void read() {
        System.out.println("【MathBook】认真学习数学开发");
    }
}

/**
 * 定义工厂
 * 通过工厂生成实例对象
 */
class BookFactory {

    public static IBook6 getInstance(String className) {
        if ("program".equalsIgnoreCase(className)) {
            return new ProgramBook6();
        } else if ("math".equalsIgnoreCase(className)) {
            return new MathBook6();
        }
        return null;
    }
}
